package com.base.service.system.controller;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.base.core.context.annotation.AuthenticationCheck;
import com.base.core.context.mvc.BaseV1Controller;
import com.base.service.system.ao.AuthAO;
import com.base.service.system.service.AuthService;
import com.base.service.system.service.RoleService;
import com.base.service.system.vo.AuthVO;
import com.gitee.magic.framework.head.vo.ListVO;
import com.gitee.magic.framework.head.vo.ObjectVO;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;

/**
 * @author start
 */
@Tag(name = "角色&权限")
@RestController
public class AuthController extends BaseV1Controller {

	@Resource
	private RoleService roleService;
	@Resource
	private AuthService authService;

	@AuthenticationCheck
	@Operation(summary="权限保存")
	@PostMapping("/v1/auth")
	public ObjectVO<Long> saveForUpdate(@RequestBody AuthAO ao) {
		return response(authService.saveForUpdate(ao.getId(), ao));
	}

	@AuthenticationCheck
	@Operation(summary="权限删除")
	@DeleteMapping("/v1/auth")
	public ObjectVO<Integer> remove(@RequestBody List<Long> ao) {
		return response(authService.remove(ao));
	}

	@AuthenticationCheck
	@Operation(summary="所有权限")
	@GetMapping("/v1/auth/tree")
	public ListVO<AuthVO> tree() {
		return response(authService.tree(0L));
	}

}
